package customer

import (
	"zsc-boot/app/customer/model"
	"zsc-boot/app/customer/router"
	"zsc-boot/app/customer/service"
	"zsc-boot/core"
	"zsc-boot/core/orm"
)

func Init() {
	router.InitCustomerChannelRouterGroup()
	router.InitCustomerImportRouterGroup()
	router.InitCustomerRouterGroup()
	router.InitOrderRouterGroup()
	router.InitReportRouterGroup()

	orm.AutoMigrate(model.CustomerChannel{}, model.Customer{}, model.CustomerImportLog{},
		model.CustomerFollowLog{}, model.CustomerFlowLog{}, model.CustomerFollowRemind{},
		model.Order{}, model.OrderAdd{}, model.CustomerNewLog{})

	//每分钟查看是否有需要有提醒跟进的客户
	core.RegCron("* * * * *", new(service.CustomerSvc).CronRemind)
	//每天早上八点清洗客户
	core.RegCron("1 0 * * *", new(service.CustomerSvc).CronClear)
	core.RegCron("1 * * * *", func() {
		if err := service.NewCustomerChannel().CallBack(); err != nil {
			core.GetLogger().Error("回调异常" + err.Error())
			return
		}
	})
	core.RegCron("*/5 * * * *", func() {
		core.GetLogger().Error("开始执行拉取")
		if err := service.NewCustomerChannel().PullSk(); err != nil {
			core.GetLogger().Error("拉取异常" + err.Error())
			return
		}
		core.GetLogger().Error("结束执行拉取")
	})

	core.RegCron("* * * * *", func() {
		core.GetLogger().Info("开始定时自动分配")
		if err := new(service.CustomerSvc).AutoAssigned(); err != nil {
			core.GetLogger().Error("定时自动分配异常:" + err.Error())
		}
	})
}
